package com.lanou.musicbox.adapter.onlinemusic;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.EnterSingers;

import java.util.ArrayList;

/**
 * Created by 柳柏庆 on 15/10/27.
 * 网络音乐_进入歌手页面Adapter
 */
public class EnterSingersListAdapter extends BaseAdapter {

    private ArrayList<EnterSingers.DataEntity> data;
    private Context context;

    public EnterSingersListAdapter(Context context, ArrayList<EnterSingers.DataEntity> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.singers_enter, null);
            viewHolder = new ViewHolder();
            viewHolder.singerName = (TextView) convertView.findViewById(R.id.singers_song);
            viewHolder.name = (TextView) convertView.findViewById(R.id.singers_singer);
            viewHolder.favorites = (TextView) convertView.findViewById(R.id.singers_enter_number);
            viewHolder.listnumber = (TextView) convertView.findViewById(R.id.listnumber);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        EnterSingers.DataEntity entity = (EnterSingers.DataEntity) getItem(position);
        viewHolder.name.setText(entity.getSingerName());
        Log.i("LANOU", entity.getSingerName() + "++++");
        viewHolder.singerName.setText(entity.getName());
        viewHolder.favorites.setText(entity.getFavorites());
        viewHolder.listnumber.setText(position + 1 + "");
        return convertView;
    }

    class ViewHolder {
        private TextView singerName;
        private TextView name;
        private TextView favorites;
        private TextView listnumber;

    }
}
